package cjyyp.文件编程;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

@Slf4j
public class 两个filechannel传输数据 {
    static String fromPath = "F:\\LearningMaterials\\netty,nio黑马\\netty\\nio\\src\\main\\resources\\from.txt";
    static String toPath = "F:\\LearningMaterials\\netty,nio黑马\\netty\\nio\\src\\main\\resources\\to.txt";

    public static void main(String[] args) throws IOException {
        FileChannel from = new FileInputStream(fromPath).getChannel();
        FileChannel to = new FileOutputStream(toPath).getChannel();
        //效率高，底层会使用零拷贝
        //todo 这个方法一次最多传输2g数据
        long transferTo = from.transferTo(0, from.size(), to);//返回实际传输的字节数
        log.info("传输完成");
    }
}
